function debounce(fn, delay) {
    let timer = null;
    return (...args) => {
        cleartimeout(timer);
        timer = setTimeout(function () {
            fn.apply(this, args);
            cleartimeout(timer);
        }, delay);
    }
}